﻿import QtQuick 2.0
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.2
import QtQuick.Controls 2.12
import QtMultimedia 5.14
import "../components/"

Rectangle {
    id: root
//    title: "报告文件"
//    modality: Qt.WindowModal
//    flags: Qt.Window | Qt.WindowTitleHint |Qt.WindowSystemMenuHint | Qt.WindowCloseButtonHint

//    signal accepted()
//    signal rejected()

    onVisibleChanged: {
        edit_path.setText(CReport.getExportPath())
        exportType = CReport.getExportType()
        button_autoExport.checked = CReport.getAutoExport()
    }

    property int exportType: 0      // 0:Word 1:Excel 2:CSV

//    height: 445*dp;  width: 666*dp
    radius: 4*dp

    Item{
        y: 140*dp
        anchors.horizontalCenter: parent.horizontalCenter
        width: 440*dp; height: parent.height-140*dp
        Column{
            anchors.fill: parent
            spacing: 20*dp
            Row{
                spacing: 10*dp
                y:40*dp
                CustomInputText{
                    id: edit_path
                    titleWidth: 100*dp
                    editWidth: 288*dp
                    title: "报告导出路径"
                    editable: false
                }
                PushButton{
                    defaultMode2: true
                    title: "选择路径"
                    onReleased: {
                        let path = CReport.selectExportPath()
                        if(path !== ""){
                            edit_path.setText(path)
                        }
                    }
                }
            }
            Row{
                spacing: 10*dp
                height: 90*dp
                Item{
                    width: 90*dp; height: 85*dp
                    Text {
                        anchors.verticalCenter: parent.verticalCenter
                        width: 90*dp
                        text: "导出文件类型"
                        font.pixelSize: config.fontsize
                    }
                }
                ExportTypeItem{
                    checked: exportType === 0
                    title: "Word"
                    color_selected: "#1677FF"
                    icon_source: "qrc:/picture/exportItem_word.png"
                    onClicked: {
                        exportType = 0
                    }
                }
        //        ExportTypeItem{
        //            checked: exportType === 1
        //            title: "Excel"
        //            color_selected: Qt.rgba(3/255, 159/255, 0, 0.9)
        //            icon_source: "qrc:/picture/exportItem_excel.png"
        //            onClicked: {
        //                exportType = 1
        //            }
        //        }
        //        ExportTypeItem{
        //            checked: exportType === 2
        //            title: "Csv"
        //            color_selected: Qt.rgba(3/255, 159/255, 0, 0.9)
        //            icon_source: "qrc:/picture/exportItem_csv.png"
        //            onClicked: {
        //                exportType = 2
        //            }
        //        }
            }
            Row{
                spacing: 10*dp
                height: 30*dp
                Text {
                    anchors.verticalCenter: parent.verticalCenter
                    width: 100*dp
                    text: "是否自动导出"
                    font.pixelSize: config.fontsize
                }
                CustomSwitchButton{
                    id: button_autoExport
                    onClicked: {
                        checked = !checked
                    }
                }
            }
            Text {
                height: 30*dp
                text: qsTr("<font color='red'>*</font>注：选择开启即实验完成后自动导出报告到上面路径下")
            }
            Rectangle { height: 0.00001*dp; width: 20*dp }
            PushButton{
                title: "确定"
                defaultMode1: true
                anchors.right: parent.right
                onReleased: {
                    if(CReport.updateExportInfo(edit_path.getText(), exportType, button_autoExport.checked)){
                        toast_settings.show("保存成功", 0)
                    }else{
                        toast_settings.show("所选目录没有保存权限", 1)
                    }
                }
            }
        }
    }
}
